1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.fhw.cabaweb.webfrontend.filters;
20
21 import java.io.IOException;
22
23 import javax.servlet.Filter;
24 import javax.servlet.FilterChain;
25 import javax.servlet.FilterConfig;
26 import javax.servlet.ServletException;
27 import javax.servlet.ServletRequest;
28 import javax.servlet.ServletResponse;
29 import javax.servlet.http.HttpServletRequest;
30 import javax.servlet.http.HttpServletResponse;
31
32 import org.apache.commons.logging.Log;
33 import org.apache.commons.logging.LogFactory;
34
35 /***
36 * <strong>Filter</strong>-Klasse die im Falle das der Client das unterstützt,
37 * den Stream GZIP komprimiert.
38 *
39 * ORIGINAL aus dem Buch Servlets and JavaServer Pages
40 * von Jayson Falkner, Kevin Jones (http://www.jspbook.com/)
41 *
42 * @author Jayson Falkner, Kevin Jones
43 *
44 * @version Version 1.0 24.07.2004
45 */
46 public class GZIPFilter implements Filter
47 {
48 /***
49 * The <code>Log</code> instance for this application.
50 */
51 private Log log = LogFactory.getLog("org.fhw.cabaweb.webfrontend.filters");
52
53 public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException
54 {
55 if (req instanceof HttpServletRequest)
56 {
57 HttpServletRequest request = (HttpServletRequest) req;
58 HttpServletResponse response = (HttpServletResponse) res;
59 String ae = request.getHeader("accept-encoding");
60
61 if (ae != null && ae.indexOf("gzip") != -1)
62 {
63 if (log.isDebugEnabled())
64 {
65 log.debug(" GZIP supported, compressing.");
66 }
67
68 GZIPResponseWrapper wrappedResponse = new GZIPResponseWrapper(response);
69 chain.doFilter(req, wrappedResponse);
70 wrappedResponse.finishResponse();
71
72 return;
73 }
74
75 chain.doFilter(req, res);
76 }
77 }
78
79 public void init(FilterConfig filterConfig)
80 {
81
82 }
83
84 public void destroy()
85 {
86
87 }
88 }